package vmcs.simulationsystem;

import java.awt.BorderLayout;
import java.awt.Checkbox;
import java.awt.Dialog;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.Panel;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import vmcs.controller.MachineryController;
import vmcs.machinery.Door;
import vmcs.store.Store;
import vmcs.store.StoreController;
import vmcs.ui.interfacecontrol.IMachineryPanel;
import vmcs.ui.interfacecontrol.ISimulatorPanel;

/**
 * This class instantiates the Machinery simulator panel which simulates the
 * physical actions of the maintainer. It enables the user to:
 * 1 display and enter new values for the number of cans of each {@link DrinksBrand} 
 * held by the {@link DrinksStore}.
 * 2 display and enter new values for the number of {@link Coin} of each denomination
 * held by the {@link CashStore}.
 * 3 display whether the vending machine {@link Door} is unlocked, and enable it to 
 * locked. This class inherits for JAVA AWT Dialog class.
 *
 */

public class MachinerySimulationPanel implements IMachineryPanel {

        private StoreViewer cashDisplay;
		private StoreViewer drinksDisplay;
        private Checkbox doorDisplay;
        private Dialog dialog;

/**
 * This constructor creates an instance of the Machinery Simulator Panel. It further
 * creates Drinks Store Display, Cash Store Display and Door Status DIsplay. It
 * receives and keeps the reference for Store Controller
 * @param fr
 * @param machCtrl
 * @see MachineryController
 */
        public MachinerySimulationPanel() {
        }
        
        public StoreViewer getCashDisplay() {
			return cashDisplay;
		}

		public void setCashDisplay(StoreViewer cashDisplay) {
			this.cashDisplay = cashDisplay;
		}

		public StoreViewer getDrinksDisplay() {
			return drinksDisplay;
		}

		public void setDrinksDisplay(StoreViewer drinksDisplay) {
			this.drinksDisplay = drinksDisplay;
		}

		public Checkbox getDoorDisplay() {
			return doorDisplay;
		}

		public void setDoorDisplay(Checkbox doorDisplay) {
			this.doorDisplay = doorDisplay;
		}

		public Dialog getDialog() {
			return dialog;
		}

		public void setDialog(Dialog dialog) {
			this.dialog = dialog;
		}

/**
 * This method display the Machinery Simulator Panel. This will be achieved by
 * displaying the frame of the panel and then sending messages to its constituent
 * objects instructing them to:
 * 1 display themselves, 2 set initial value and 3 deactivate themselves.
 */
        @Override
        public void display() {
        	dialog.setVisible(true);
        }

/**
 * Remove the panel objects and Machinery Simulator Panel from the display.
 */
        @Override
        public void closeDown() {
        	dialog.dispose();
        }

/**
 * Retrieves the Cash Store Display object
 * @return cashDisplay retrieves Store Viewer Object
 * @see StoreViewer
 */
        /*public StoreViewer getCashStoreDisplay() {
                return cashDisplay;
        }*/

/**
 * Retrieves the Drinks Store Display object
 * @return drinkDisplay retrieves Store Viewer Object
 * @see StoreViewer
 */
        /*public StoreViewer getDrinksStoreDisplay() {
                return drinksDisplay;
        }*/

/**
 * This methods set state of the Door object
 * @param state Either Open or Close
 */     
    	@Override
        public void setDoorState(boolean state) {
                doorDisplay.setState(state);
                this.setActive(!state);

        }

/**
 * This operation activates or deactivates the Machinery Simulator Panel and its
 * component objects
 * @param state This state is active or deactive (true or false)
 * @see StoreViewer
 */     
        public void setActive(boolean state) {
                cashDisplay.setActive(state);
                drinksDisplay.setActive(state);
                doorDisplay.setEnabled(state);
        }

	@Override
	public void showMessage(String message) {
		MessageDialog msg =
	            new MessageDialog(dialog, message);
	    msg.setVisible(true);
		
	}

	@Override
	public void updateDrinksStoreDisplay() {
		drinksDisplay.update();
		
	}

	@Override
	public void updateCashStoreDisplay() {
		cashDisplay.update();		
	}
}